package com.demo11.d17_03.HalfClose;

import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author: root
 * @Date: 2018/12/5 17:16
 */
public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(30000);
        Socket socket = serverSocket.accept();
        PrintStream ps = new PrintStream(socket.getOutputStream());
        ps.println("服务器的第一行数据");
        ps.println("服务器的第二行数据");
        // 关闭socket的输出流，表明输出数据已经结束
        socket.shutdownOutput();
        // 下面语句将输出false，表明socket还未关闭。
        System.out.println(socket.isClosed());
        Scanner scan = new Scanner(socket.getInputStream());
        while (scan.hasNextLine()) {
            System.out.println(scan.nextLine());
        }
        scan.close();
        socket.close();
        serverSocket.close();
    }
}
